package com.evil.common.application.enums.permission;

import com.evil.common.core.enums.RCodeEnum;
import com.evil.common.core.enums.SwitchEnum;
import com.evil.common.core.exception.BusinessException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;
import java.util.function.Function;

/**
 * 流程负责人权限变动类型
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@AllArgsConstructor
public enum ChangeTypeEnum {

    /**
     * 添加流程负责人还是移出流程负责人
     */
    ADD(1, "添加", SwitchEnum::isClose),
    DELETE(2, "删除", SwitchEnum::isOpen),
    ;

    @Getter
    private final int id;
    @Getter
    private final String name;
    @Getter
    private final Function<Integer, Boolean> isDeleted;

    public static Optional<ChangeTypeEnum> findById(int id) {
        return Arrays.stream(values()).filter(e -> e.id == id).findFirst();
    }

    public static BusinessException getBusinessException() {
        return new BusinessException(RCodeEnum.ERROR_PARAMETER);
    }
}
